package com.holyant.report.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.domain.BaseDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 产品仓库动销统计dto
 * 
 * @author holyant
 * @date 2021-09-22
 */
@Data
@ApiModel("产品仓库动销统计")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RptSkuWarehouseGmvDto extends BaseDto {


    private static final String NO_STOCK= "无库存";
    private static final String NO_MOVABLE_PIN= "无动销";


    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "首单日期")
    private LocalDateTime firstOrderDate;

    @ApiModelProperty(value = "累计总销量")
    private BigDecimal totalSalesQtys;

    @ApiModelProperty(value = "累计日均销量")
    private BigDecimal totalAverageDailySales;

    /** 销量 */
    @Excel(name = "当月销量")
    @ApiModelProperty(value = "当月销量")
    private BigDecimal salesQty;

    /** 销售额 */
    @Excel(name = "销售额")
    @ApiModelProperty(value = "销售额")
    private BigDecimal salesAmount;

    @ApiModelProperty(value = "日均销售")
    private BigDecimal averageDailySales;

    /**
     * 剩余库存可售天数
     */
    @ApiModelProperty(value = "剩余库存可售天数")
    private String surplusStockDay;

    /** 账期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "账期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "账期")
    private LocalDate accountDate;

    /** skuid */
    @Excel(name = "skuid")
    @ApiModelProperty(value = "skuid")
    private Long skuId;

    /** sku名称 */
    @Excel(name = "sku名称")
    @ApiModelProperty(value = "sku名称")
    private String skuName;

    /** 仓库id */
    @Excel(name = "仓库id")
    @ApiModelProperty(value = "仓库id")
    private Long warehouseId;

    /** 仓库名称 */
    @Excel(name = "仓库名称")
    @ApiModelProperty(value = "仓库名称")
    private String warehouseName;

    /** 失效日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "失效日期", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "失效日期")
    private LocalDate expireDate;

    /** $column.columnComment */
    @Excel(name = "失效日期")
    @ApiModelProperty(value = "失效日期")
    private Long goodsId;

    /** 商品名称 */
    @Excel(name = "商品名称")
    @ApiModelProperty(value = "商品名称")
    private String goodsName;

    /** 商品条码 */
    @Excel(name = "商品条码")
    @ApiModelProperty(value = "商品条码")
    private String barcode;

    /** 品牌id */
    @Excel(name = "品牌id")
    @ApiModelProperty(value = "品牌id")
    private Long brandId;

    /** 品牌名称 */
    @Excel(name = "品牌名称")
    @ApiModelProperty(value = "品牌名称")
    private String brandName;

    /** 备注 */
    @Excel(name = "备注")
    @ApiModelProperty(value = "备注")
    private String remark;

    /**
     * 库存数量（包含锁定冻结库存）
     * in - out
     */
    @Excel(name = "库存数量（包含锁定冻结库存）")
    @ApiModelProperty(value = "库存数量（包含锁定冻结库存）")
    private BigDecimal allQty;

    /** 采购在途数量 */
    @ApiModelProperty(value = "采购在途数量")
    private BigDecimal purchaseTransitQty;

    /**
     * 时间范围
     */
    private String valueDate;


    public String getSurplusStockDay() {
        if (Objects.isNull(allQty) || allQty.compareTo(BigDecimal.ZERO) == 0)return NO_STOCK;
        if (Objects.isNull(salesQty) || salesQty.compareTo(BigDecimal.ZERO) == 0)return NO_MOVABLE_PIN;
        return allQty.divide(salesQty,4,BigDecimal.ROUND_HALF_UP).toString();
    }
}
